/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package driver;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import org.xml.sax.SAXException;
import web.ConfigEnv;


/**
 *
 * @author keith
 */
public class Driver {

  public static void main( String[] args ) throws FileNotFoundException,
                                                  IOException, SAXException,
                                                  TransformerConfigurationException,
                                                  ParserConfigurationException,
                                                  TransformerException {
    final Logger myLogger = AppLog.appLog;

    String outDirName = null;

    if ( args.length != 5 ) {
      System.out.println( "usage: " );
      System.out.println( 
        "\t{configDir} {boumlProj} {boumlPlugoutJar} {xsl} {outDir}" );
      System.exit( 1 );
    }

    final String configDir = args[0];
    final File boumlProj = new File( args[1] );
    final File plugoutJar = new File( args[2] );
    final File xslFile = new File( args[3] );
    final File outDir = new File( args[4] );

    final ConfigEnv configEnv = ConfigEnv.getConfiguration( configDir );
    if ( !configEnv.isValid() ) {
      myLogger.log( Level.SEVERE, "Invalid configuration file: " + configDir );
    } else if ( !outDir.exists() ) {
      myLogger.log( Level.SEVERE,
                    "baseDir: \"" + outDirName + "\" does not exist." );
    } else {
      final GoogleGroupWebExtract process =
        new GoogleGroupWebExtract( configEnv, outDir );

      process.start();

      process.driver();

      if ( xslFile.exists() ) {
        Bouml b = new Bouml( boumlProj, plugoutJar, xslFile, outDir );

        b.driver();
      }
    }

    myLogger.log( Level.INFO, "Done." );
  }
}
